package com.summer.data.spring;

import com.summer.data.dialect.Dialect;
import com.summer.data.rs.Extractor;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 345480567@qq.com
 */
public class ResultSetExtractorAdapter<T> implements ResultSetExtractor<T> {

    private final Extractor<T> extractor;

    private final Dialect dialect;

    public ResultSetExtractorAdapter(Extractor<T> extractor, Dialect dialect) {
        this.extractor = extractor;
        this.dialect = dialect;
    }

    @Override
    public T extractData(ResultSet rs) throws SQLException, DataAccessException {
        return extractor.extract(rs, dialect);
    }
}
